<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8"></meta>
		<title>layui</title>
		<meta name="renderer" content="webkit"></meta>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></meta>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"></meta>
		<link rel="stylesheet" href="layui/css/layui.css" media="all"></link>
	</head>
	<body>
	<style>
	img{
	width:50px;
	lheight:50px;
	}
	</style>
 <script src="layui/layui.js"></script>
 
		<table class="layui-table" id="demo" lay-filter="demo"></table>
	 
<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">修改状态</a>
		</script>
		<script src="layui/layui.js"></script> 
		<script src="js/jquery-3.3.1.min.js"></script>
 <script>

 layui.use('table', function() {
		var table = layui.table,
			form = layui.form;
		
			tableIns=table.render({
				elem: '#demo',
				url: 'userenrollment',
				id: 'idTest',
				page:"true",
				cellMinWidth: 80,
					// ,height: 'full-50%'
				cols: [
					[ 
						{
							field: 'id',
							title: 'ID',
							width: 80,
							sort: true,
							fixed: true
						}, {
							field: 'userEnrollmentSchool',
							title: '学校',
							width: 200
						},
						{
							field: 'userName',
							title: '姓名',
							width: 200 
						},
						{
							field: 'userStatus',
							title: '是否可以包名',
							width: 200 
						},
						{
							field: 'userEnrollmentNum',
							title: '学号',
							width: 200,
							sort: true
						}, {
							field: 'userEnrollmentMajor',
							title: '专业',
							width: 100
						},
						{
							field: 'idNumber',
							title: '身份证号',
							width: 100
						},{
							field: 'right',
							width: 178,
							align: 'center',
							toolbar: '#barDemo'
						}
					]
				],
				done: function(res, curr, count){
    				
     pageCurr=curr;
 }
			});
		/*}*/

		//监听工具条

		table.on('tool(demo)', function(obj) {

			var data = obj.data;
		  if(obj.event === 'edit') { //编辑修改
				//alert(data);
			console.log(data.id);
			
				//回显数据
				$.get("edituserbyid", {
					"id": data.id
				}, function(data) {
					if(data.code == "1000") {
						layer.alert("修改成功！");
						load(obj);
					} else {
						//弹出错误提示
						layer.alert(data.msg, function() {
							layer.closeAll();
							
						});
					}
				});
		 
			
			}
		});

		 
		$('.demoTable .layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		
	 
	});
 /* 日期控件 */
 layui.use('laydate', function(){
	  var laydate = layui.laydate;
	  
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#ExaminationInformationTime' //指定元素
	  });
	  laydate.render({
		    elem: '#Time' //指定元素
		  });
	});
 
  
	function getexamid(obj, id) {
		//回显数据
		$.get("getexamid", {
			"Id": id
		}, function(data) {
			if(data.code == "1000") {
				$("#ExaminationInformationID").val(data.obj.examinationInformationID == null ? '' :  data.obj.examinationInformationID);
				$("#ExaminationInformationName").val(data.obj.examinationInformationName == null ? '' :  data.obj.examinationInformationName);
				$("#ExaminationInformationCost").val(data.obj.examinationInformationCost == null ? '' :  data.obj.examinationInformationCost);
				$("#ExaminationInformationTime").val(data.obj.examinationInformationTime == null ? '' :  data.obj.examinationInformationTime);
				editexam("更新考试信息");
			
			} else {
				//弹出错误提示
				layer.alert(data.msg, function() {
					layer.closeAll();
					
				});
			}
		});
	}
	
	function formaddSubmit(obj) {
		$.ajax({
			url: "addexam",
			contentType: "application/json; charset=utf-8",  
		    dataType: "json",  
			type: "POST",
			async: true,
		    timeout: 50000,
			data: JSON.stringify({                    
				"examinationInformationID": $("#ID").val(),  
				"examinationInformationName": $("#Name").val(),  
				"examinationInformationCost": $("#Cost").val(),
				"examinationInformationTime": $("#Time").val()
	        }),
			success: function(data) { 
				if(data.code == "1000")
					{
					layer.alert("操作成功", function() {
						layer.closeAll();
						load(obj);
					});
				} else {
				  layer.alert(data);
				}
			} ,
			  error: function() {
				layer.alert("操作请求错误，请您稍后再试", function() {
					layer.closeAll();
					 load(obj); //自定义
				 
				});
			}  
		});
	}
	
	
	function formSubmit(obj) {
		$.ajax({
			url: "updateexam",
			contentType: "application/json; charset=utf-8",  
		    dataType: "json",  
			type: "POST",
			async: true,
		    timeout: 50000,
			data: JSON.stringify({                    
				"examinationInformationID": $("#ExaminationInformationID").val(),  
				"examinationInformationName": $("#ExaminationInformationName").val(),  
				"examinationInformationCost": $("#ExaminationInformationCost").val(),
				"examinationInformationTime": $("#ExaminationInformationTime").val()
	        }),
			
			success: function(data) {
				 
				if(data.code == "1000")
					{
					layer.alert("操作成功", function() {
						layer.closeAll();
						load(obj);
					});
				} else {
				  layer.alert(data);
				}
			} ,
			  error: function() {
				layer.alert("操作请求错误，请您稍后再试", function() {
					layer.closeAll();
					//加载load方法
					 load(obj); //自定义
				 
				});
			}  
		});
	}
function load(obj){
//重新加载table
tableIns.reload({
where: obj.field
, page: {
 curr: pageCurr //从当前页码开始
}
});
} 

function addexam(title) {
	layer.open({
		type: 1,
		title: title,
		fixed: false,
		resize: false,
		shadeClose: true,
		area: ['550px'],
		content: $('#addexam')
	});
}

	function editexam(title) {
		layer.open({
			type: 1,
			title: title,
			fixed: false,
			resize: false,
			shadeClose: true,
			area: ['550px'],
			content: $('#editexam')
		});
	}
 </script>
	</body>
</html>